<?
/*
 *  GGB - Gelin's Guest Book.
 *  Copyright (C) 2006-2009 Denis Nelubin aka Gelin
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *  http://gelin.ru
 *  mailto:den@gelin.ru
 *
 *  Description:    Formatter for messages and other elements of admin pages.
 *
 *  History:
 *  2006-08-05  Gelin   Initially created.
 *  2007-01-07  Gelin   added ban form functionality
 *  2009-10-14  Gelin   added setMessageType()
 *
 */

require_once('MessageType.php');
require_once('Formatter.php');
require_once('LoginForm.php');
require_once('BanForm.php');
require_once('AdminMessageForm.php');
require_once('AdminPagesFormatter.php');
require_once('AdminMessageFormatter.php');

/**
 *  Formatter for messages and other elements of admin pages.
 */
class AdminFormatter extends Formatter {

    /** form for login admin */
    var $loginForm;
    /** form for ban IP */
    var $banForm;

    /** constructor */
    function AdminFormatter() {
        parent::Formatter();
        $this->loginForm = new LoginForm();
        $this->banForm = new BanForm();
        $this->messageForm = new AdminMessageForm();
        $this->pagesFormatter = new AdminPagesFormatter();
        $this->messageFormatter = new AdminMessageFormatter();
    }

    /**
     *  Sets the message type to be formatted.
     *  @param  $messageType    message type to format
     */
    function setMessageType($messageType = APPROVED_MESSAGE) {
        $this->pagesFormatter->setMessageType($messageType);
    }

    /**
     *  Creates array of form fields for admin login form.
     *  @return array of form fields.
     */
    function prepareLoginForm() {
        return $this->loginForm->prepareForm();
    }

    /**
     *  Gets admin login information from request.
     *  @return array with admin params.
     */
    function getLoginFromRequest() {
        return $this->loginForm->getFromRequest();
    }

    /**
     *  Creates array of form fields for add message form.
     *  @return array of form fields.
     */
    function prepareAddForm() {
        return $this->messageForm->prepareAddForm();
    }

    /**
     *  Creates array of form fields for edit message form.
     *  Fields are populated by values extracted from database.
     *  @param  $message   message which will be edited.
     *  @return array of form fields.
     */
    function prepareEditForm($message) {
        return $this->messageForm->prepareEditForm($message);
    }

    /**
     *  Creates array of form fields for delete message form.
     *  @param  $message   message which will be deleted.
     *  @return array of form fields.
     */
    function prepareDeleteForm($message) {
        return $this->messageForm->prepareDeleteForm($message);
    }

    /**
     *  Creates array of form fields for ban form.
     *  @return array of form fields.
     */
    function prepareBanForm() {
        return $this->banForm->prepareForm();
    }

    /**
     *  Gets ban from fields from request.
     *  @return array with form fields
     */
    function getBanFromRequest() {
        return $this->banForm->getFromRequest();
    }

    /**
     *  Prepares ban form to display
     *  @param  $ban array of ban fields to prepare
     *  @return modified array of ban fields
     */
    function prepareBanToDisplay($ban) {
        return $this->banForm->prepareToDisplay($ban);
    }

}

?>